package cn.hg.solon.youcan.framework.provider;

import java.util.List;

import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

import cn.hg.solon.youcan.framework.cache.YoucanCacheService;
import cn.hg.solon.youcan.framework.service.CacheService;

/**
 * @author 胡高
 */
@Component
public class CacheProvider implements CacheService {

    @Inject
    YoucanCacheService cacheTagsService;

    @Override
    public void clearAll() {
        List<?> cacheNames = this.getCacheNames();
        for (Object cacheName : cacheNames) {
            if (cacheName instanceof String) {
                this.clearCacheNames((String)cacheName);
            }
        }
    }

    @Override
    public void clearCacheKey(String cacheName, String cacheKey) {
        this.cacheTagsService.remove(cacheKey, cacheName);
    }

    @Override
    public void clearCacheNames(String... cacheNames) {
        this.cacheTagsService.removeTag(cacheNames);
    }

    @Override
    public List<?> getCacheKeys(String cacheName) {
        return this.cacheTagsService.getKeys(cacheName);
    }

    @Override
    public List<?> getCacheNames() {
        return this.cacheTagsService.getTags();
    }

    @Override
    public Object getCacheValue(String cacheName, String cacheKey) {
        return this.cacheTagsService.get(cacheKey, cacheName);
    }

}
